
function BasicTrack(time, loop)
{
    if (this instanceof BasicTrack)
    {
        if (arguments.length == 0) return;
        assert(time >= 0, "Track time must >= 0!");
        this.totalTime = time;
        this.curTime = 0;
        this.loop = loop;
    }
    else
    {
        return new BasicTrack(time, loop);
    }
}

BasicTrack.prototype.update = function(interval)
{
	if (this.totalTime <= 0) return;
	this.curTime += interval;
	if (this.loop)
	{
		while(this.curTime > this.totalTime)
		{
			this.curTime -= this.totalTime;
		}
	}
	else
	{
		if (this.curTime > this.totalTime)
		{
			this.curTime = this.totalTime;
		}
	}
}

BasicTrack.prototype.start = function()
{
	this.curTime = 0;
}

BasicTrack.prototype.end = function()
{
	this.curTime = this.totalTime;
}

BasicTrack.prototype.isEnd = function()
{
	return !this.loop && this.curTime >= this.totalTime;
}

function MoveTrack(startPos, endPos, time, loop)
{
    if (this instanceof MoveTrack)
    {
        BasicTrack.call(this, time, loop);
        this.startPos = startPos.clone();
        this.endPos = endPos.clone();
    }
    else
    {
        return new MoveTrack(startPos, endPos, time, loop);
    }
}

inheritPrototype(MoveTrack, BasicTrack);

MoveTrack.prototype.getCurOffset = function()
{
	if (this.totalTime == 0)
	{
		return this.startPos;
	}
   return Point.s_add(this.startPos, Point.s_mul(Point.s_sub(this.endPos, this.startPos), (this.curTime / this.totalTime))); 
}
